//////////////////////////////////////////////////////////////////
// MattiseOS Kernel
// Date: 2008
// Author: Matthew Iselin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////

// Includes
#include <mattise.h>
#include <stdint.h>
#include <mem/util.h>
#include <core/dts.h>
#include <core/portio.h>
#include <core/intrcommon.h>

// Prototypes

// IRQ entry routines
void irq_0();
void irq_1();
void irq_2();
void irq_3();
void irq_4();
void irq_5();
void irq_6();
void irq_7();
void irq_8();
void irq_9();
void irq_10();
void irq_11();
void irq_12();
void irq_13();
void irq_14();
void irq_15();

// Functions

void kSetupIRQs()
{
	// reprogram the PIC to make IRQ interrupts start at 42
	outb( 0x20, 0x11 );
	outb( 0xa0, 0x11 );
	outb( 0x21, 0x20 );
	outb( 0xa1, 0x28 );
	outb( 0x21, 0x04 );
	outb( 0xa1, 0x02 );
	outb( 0x21, 0x01 );
	outb( 0xa1, 0x01 );
	outb( 0x21, 0x0 );
	outb( 0xa1, 0x0 );

	// install the IRQs
	kIdtSetGate( 32, (uint32_t) irq_0, 0x08, 0x8E );
	kIdtSetGate( 33, (uint32_t) irq_1, 0x08, 0x8E );
	kIdtSetGate( 34, (uint32_t) irq_2, 0x08, 0x8E );
	kIdtSetGate( 35, (uint32_t) irq_3, 0x08, 0x8E );
	kIdtSetGate( 36, (uint32_t) irq_4, 0x08, 0x8E );
	kIdtSetGate( 37, (uint32_t) irq_5, 0x08, 0x8E );
	kIdtSetGate( 38, (uint32_t) irq_6, 0x08, 0x8E );
	kIdtSetGate( 39, (uint32_t) irq_7, 0x08, 0x8E );
	kIdtSetGate( 40, (uint32_t) irq_8, 0x08, 0x8E );
	kIdtSetGate( 41, (uint32_t) irq_9, 0x08, 0x8E );
	kIdtSetGate( 42, (uint32_t) irq_10, 0x08, 0x8E );
	kIdtSetGate( 43, (uint32_t) irq_11, 0x08, 0x8E );
	kIdtSetGate( 44, (uint32_t) irq_12, 0x08, 0x8E );
	kIdtSetGate( 45, (uint32_t) irq_13, 0x08, 0x8E );
	kIdtSetGate( 46, (uint32_t) irq_14, 0x08, 0x8E );
	kIdtSetGate( 47, (uint32_t) irq_15, 0x08, 0x8E );
}
